﻿using System;
using System.Collections.Generic;
using System.Web;
using webapp4U.DAL;

namespace webapp4U.BOL
{
    public class PhotoCategory
    {
        #region "======Properties====="

        private int _cateID;
        private string _appkey;
        private string _cateName;
        private string _cateDesc;
        private string _cateName_en;
        private string _cateDesc_en;
        private string _imageUrl;
        private int _cateOrder;
        private int _parentCateID;


        public int CateID
        {
            get { return _cateID; }
            set { _cateID = value; }
        }

        public string AppKey
        {
            get { return _appkey; }
            set { _appkey = value; }
        }

        public string CateName
        {
            get { return _cateName; }
            set { _cateName = value; }
        }


        public string CateDesc
        {
            get { return _cateDesc; }
            set { _cateDesc = value; }
        }


        public string CateName_en
        {
            get { return _cateName_en; }
            set { _cateName_en = value; }
        }


        public string CateDesc_en
        {
            get { return _cateDesc_en; }
            set { _cateDesc_en = value; }
        }


        public string ImageUrl
        {
            get { return _imageUrl; }
            set { _imageUrl = value; }
        }


        public int CateOrder
        {
            get { return _cateOrder; }
            set { _cateOrder = value; }
        }


        public int ParentCateID
        {
            get { return _parentCateID; }
            set { _parentCateID = value; }
        }


        #endregion


        #region "==== Method ===="


        public PhotoCategory()
        {

        }

        // lay Albums dau tien
        public static int GetTop1Albums()
        {
            List<PhotoCategory> obj = PhotoCategory.GetAlbums();
            foreach (PhotoCategory fcate in obj)
            {
                return fcate.CateID;
            }
            return -1;
        }


        // lay duong dan cua file hinh dai dien cho Albums
        public static string GetPathByCateID(int CateID)
        {
            PhotoCategoryDAL db = new PhotoCategoryDAL();
            string path = System.Web.HttpContext.Current.Server.MapPath("~/Gallery/");
            PhotoCategory obj = db.GetCateByCateID(CateID);
            if (obj.ImageUrl != null && obj.ImageUrl != "")
                path = path + obj.AppKey + "\\"+ obj.ImageUrl;
            else
                path = "";
            return path;
        }


        public static string GetAppKeyByCateID(int CateID)
        {
            PhotoCategoryDAL db = new PhotoCategoryDAL();
            return db.GetAppKeyByCateID(CateID);
        }


        public static bool CheckAppKey(string AppKey)
        {
            PhotoCategoryDAL db = new PhotoCategoryDAL();
            return db.CheckAppKey(AppKey);
        }



        // lay Albums 
        public static List<PhotoCategory> GetAlbums()
        {
            PhotoCategoryDAL db = new PhotoCategoryDAL();
            return db.GetAlbums();
        }

        public static List<PhotoCategory> GetCateByParentCateID(int ParentCateID)
        {
            PhotoCategoryDAL db = new PhotoCategoryDAL();
            return db.GetCateByParentCateID(ParentCateID);
        }

        public static PhotoCategory GetCateByCateID(int CateID)
        {
            PhotoCategoryDAL db = new PhotoCategoryDAL();
            return db.GetCateByCateID(CateID);
        }

        public static int Insert(PhotoCategory obj)
        {
            PhotoCategoryDAL db = new PhotoCategoryDAL();
            return db.Insert(obj);
        }

        public static int Update(PhotoCategory obj)
        {
            PhotoCategoryDAL db = new PhotoCategoryDAL();
            return db.Update(obj);
        }


        public static int Delete(int CateID)
        {
            PhotoCategoryDAL db = new PhotoCategoryDAL();
            PhotoCategory obj = db.GetCateByCateID(CateID);
            if (System.IO.Directory.Exists(Globals.GetGalleryPath() + obj.AppKey) && (obj.AppKey.Trim()!=""))
                System.IO.Directory.Delete(Globals.GetGalleryPath() + obj.AppKey, true);
            
            return db.Delete(CateID);
        }


        #endregion


    }
}
